package main

import "fmt"

var channels = [3]chan int{
	nil,
	make(chan int),
	nil,
}

var numbers = []int{1, 2, 3}

func getNumber(i int) int {
	fmt.Printf("numbers[%d]\n", i)
	return numbers[i]
}

func getChan(i int) chan int {
	fmt.Printf("channels[%d]\n", i)
	return channels[i]
}

func main() {
	select {
	case getChan(0) <- getNumber(0):
		fmt.Println("执行第0条分支")
	case getChan(1) <- getNumber(1):
		fmt.Println("执行第1条分支")
	case getChan(2) <- getNumber(2):
		fmt.Println("执行第2条分支")
	default:
		fmt.Println("没有分支被执行")
	}
}

/* 输出:
channels[0]
numbers[0]
channels[1]
numbers[1]
channels[2]
numbers[2]
没有分支被执行
*/
